<?php

/**
 * @name: HOTN AnimeList
 * @author: HammerOnTheNail
 * @link: http://code.google.com/p/hotnanimelist/
 */

// Adatbázis lekérdezése

// Projectek
$sql->db_Select("hotn_animelist_project", "project_id, project_name, project_mode, project_type", "`project_mode` = 'active' or `project_mode` = 'finished' ORDER BY project_name ASC");
while ($row = $sql->db_Fetch())
{
	
	if ($row['project_type'] == "anime") $row['project_type'] = HOTN_ANIMELIST_DEFAULT_ANIME;
	if ($row['project_type'] == "manga") $row['project_type'] = HOTN_ANIMELIST_DEFAULT_MANGA;
	
	if ($row['project_mode'] == "finished")
	{
		$project_finished[$row['project_id']] = $row['project_name']." (".$row['project_type'].")";
	}
	if ($row['project_mode'] == "active")
	{
		$project_active[$row['project_id']] = $row['project_name']." (".$row['project_type'].")";
	}
}

$project = array(
	HOTN_ANIMELIST_ANIMETYPE_ACTIVE => $project_active,
	HOTN_ANIMELIST_ANIMETYPE_FINISHED => $project_finished
); 

// Fileok
require_once(e_HANDLER."file_class.php");
$fl = new e_file;

if($file_array = $fl->get_files(e_DOWNLOAD, "","standard",0))
{
		sort($file_array);
		foreach ($file_array as $id => $value)
		{
			$download_files[$value['fname']] = $value['fname'];
		}
}

// Category
foreach ($project_active as $project_id => $project_name)
{
	$sql->db_Select("hotn_animelist_category","`category_name`,`category_id`","`project_id` = '".$project_id."'");
	while($row = $sql->db_Fetch())
	{
		$project_category[$project_name][$row['category_id']] = $row['category_name'];
	}
}

$data = array(
		"type" => "form",
		"method" => "post",
		"action" =>  $values['action'],
		"hidden" => $values['hidden'],
		"data" => array(
					array(
						"type" => "select",
						"name" => "project_id",
						"group" => "true",
						"selected" => $values['project_id'],
						"show" => $values['project_id_show'],
						"value" => $project,
						"text" => HOTN_ANIMELIST_ADMIN_FILE_PROJECT_NAME
					),
					array(
						"type" => "select",
						"name" => "category_id",
						"group" => "true",
						"selected" => $values['category_id'],
						"value" => $project_category,
						"text" => HOTN_ANIMELIST_ADMIN_FILE_CATEGORY_ID
					),
					array(
						"type" => "select",
						"name" => "download_type",
						"text" => HOTN_ANIMELIST_ADMIN_FILE_DOWNLOAD_TYPE,
						"selected" => $values['download_type'],
						"show" => $values['download_type_show'],
						"value" => $HOTN_ANIMELIST_PROJECT->get_types()
					),
					array(
						"type" => "text",
						"name" => "download_name",
						"text" => HOTN_ANIMELIST_ADMIN_FILE_DOWNLOAD_NAME,
						"max" => "200",
						"value" => $values['download_name']
					),
					array(
						"type" => "text",
						"name" => "download_episode",
						"text" => HOTN_ANIMELIST_ADMIN_FILE_DOWNLOAD_EPISODE,
						"max" => "10",
						"show" => $values['download_episode_show'],
						"value" => $values['download_episode']
					),
					array(
						"type" => "select",
						"name" => "download_url",
						"text" => HOTN_ANIMELIST_ADMIN_FILE_DOWNLOAD_URL,
						"show" => $values['download_url_show'],
						"value" => $download_files
					),
					array(
						"type" => "text",
						"name" => "download_link",
						"text" => HOTN_ANIMELIST_ADMIN_FILE_DOWNLOAD_LINK,
						"show" => $values['download_link_show'],
						"max" => "150",
						"value" => $values['download_link']
					),
					array(
						"type" => "submit",
						"value" => HOTN_ANIMELIST_DEFAULT_FORM_ADD
					)
				)
	);
?>